/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

/**
 *
 * @author Fernando
 */
public class PredictionControl {

    public double[] lineal(double[] data) {
        double pxy, sx, sy, sx2, sy2;
        double[] res = new double[2];
        pxy = sx = sy = sx2 = sy2 = 0.0;
        for (int i = 0; i < data.length; i++) {
            sx += (i + 1);
            sy += data[i];
            sx2 += (i + 1) * (i + 1);
            sy2 += data[i] * data[i];
            pxy += (i + 1) * data[i];
        }
        res[0] = (data.length * pxy - sx * sy) / (data.length * sx2 - sx * sx);
        res[1] = (sy - res[0] * sx) / data.length;
        return res;
    }
}